package ListPractice;

import java.util.ArrayList;

/**
 * @author Xiao
 * @date 2021/7/12
 */
public class Test02 {
    /**
     * 需求：
     * 1.创建一个ArrayList集合，用于存储一些字符串："abc","def","def","ghi","def","hij","jkol"
     * 2.遍历集合，统计集合中"def"字符串一共出现了多少个
     * 3.将集合中的所有"def"字符串删除。打印删除后的集合元素
     */
    public static void main(String[] args) {
        ArrayList<String> list = new ArrayList<>();
        list.add("abc");
        list.add("def");
        list.add("def");
        list.add("ghi");
        list.add("def");
        list.add("hij");
        list.add("jkol");
        int count_def = 0;
        for (int i = 0; i < list.size(); i++) {
            String s = list.get(i);
            if ("def".equals(s)) {
                count_def++;
//                list.remove(i);
//                i--;
                list.remove(i--);
            }
        }
        System.out.println("count_def：" + count_def);
//        System.out.print("<\t");
//        for (int i = 0; i < list.size(); i++) {
//            System.out.print(list.get(i) + "\t");
//        }
//        System.out.println(">");
        System.out.println(list);
    }
}
